package com.parsechina.hpush.broker.parser;

import io.netty.handler.codec.mqtt.MqttConnectMessage;

/**
 * @author linfeng
 * @since 2016/11/22
 */
public class ConnectMessage extends PushMessage {

    private static final long serialVersionUID = -1489633482302550544L;

    private String clientId;
    private int keepAlive;
    private int protocolVersion;
    private int willQos;
    private boolean userFlag;
    private boolean passwordFlag;
    private boolean willFlag;
    private String username;
    private String password;
    private String willMessage;
    private String willTopic;
    private boolean willRetain;
    private boolean cleanSession;
    private MqttConnectMessage connectMessage;

    public ConnectMessage(MqttConnectMessage msg) {
        super(msg);
        this.connectMessage = msg;

        this.clientId = connectMessage.payload().clientIdentifier();
        this.protocolVersion = connectMessage.variableHeader().version();
        this.cleanSession = connectMessage.variableHeader().isCleanSession();
        this.userFlag = connectMessage.variableHeader().hasUserName();
        this.passwordFlag = connectMessage.variableHeader().hasPassword();
        this.password = connectMessage.payload().password();
        this.username = connectMessage.payload().userName();
        this.keepAlive = connectMessage.variableHeader().keepAliveTimeSeconds();
        this.willFlag = connectMessage.variableHeader().isWillFlag();
        this.willQos = connectMessage.variableHeader().willQos();
        this.willMessage = connectMessage.payload().willMessage();
        this.willTopic = connectMessage.payload().willTopic();
        this.willRetain = connectMessage.variableHeader().isWillRetain();
    }

    public ConnectMessage() {
    }

    public String getClientId() {
        return clientId;
    }

    public int getProtocolVersion() {
        return protocolVersion;
    }

    public boolean isCleanSession() {
        return cleanSession;
    }

    public boolean isUserFlag() {
        return userFlag;
    }

    public boolean isPasswordFlag() {
        return passwordFlag;
    }

    public String getPassword() {
        return password;
    }

    public String getUsername() {
        return username;
    }

    public int getKeepAlive() {
        return keepAlive;
    }

    public boolean isWillFlag() {
        return willFlag;
    }

    public int getWillQos() {
        return willQos;
    }

    public String getWillMessage() {
        return willMessage;
    }

    public String getWillTopic() {
        return willTopic;
    }

    public boolean isWillRetain() {
        return willRetain;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public void setKeepAlive(int keepAlive) {
        this.keepAlive = keepAlive;
    }

    public void setProtocolVersion(int protocolVersion) {
        this.protocolVersion = protocolVersion;
    }

    public void setWillQos(int willQos) {
        this.willQos = willQos;
    }

    public void setUserFlag(boolean userFlag) {
        this.userFlag = userFlag;
    }

    public void setPasswordFlag(boolean passwordFlag) {
        this.passwordFlag = passwordFlag;
    }

    public void setWillFlag(boolean willFlag) {
        this.willFlag = willFlag;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setWillMessage(String willMessage) {
        this.willMessage = willMessage;
    }

    public void setWillTopic(String willTopic) {
        this.willTopic = willTopic;
    }

    public void setWillRetain(boolean willRetain) {
        this.willRetain = willRetain;
    }

    public void setConnectMessage(MqttConnectMessage connectMessage) {
        this.connectMessage = connectMessage;
    }

    public void setCleanSession(boolean cleanSession) {
        this.cleanSession = cleanSession;
    }
}
